//
//  XHRIllDetailViewController.m
//  快医
//
//  Created by 胥鸿儒 on 16/7/5.
//  Copyright © 2016年 xuhongru. All rights reserved.
//

#import "XHRIllDetailViewController.h"

#import "XHRNetworkingToolManager.h"

#import "XHRTextFieldRightView.h"
#import "XHRIllDetailTextField.h"
@interface XHRIllDetailViewController ()

/**标题label*/
@property(nonatomic,weak)UILabel *titlLabel;

/**疾病细分框*/
@property(nonatomic,weak)UITextField *selectIllField;

/**是否确诊文本框*/
@property(nonatomic,weak)UITextField *isSureField;

/**并发症*/
@property(nonatomic,weak)UITextField *selectComplicationField;

/**是否接受过治疗*/
@property(nonatomic,weak)UITextField *isTreatedField;

/**底部医生数量的label*/
@property(nonatomic,weak)UILabel *doctorNumberLabel;
/**医生头像*/
@property(nonatomic,weak)UIImageView *doctorImageView;

/**设置底部就诊按钮*/
@property(nonatomic,weak)UIButton *bottomButton;

/**受治疗的详细信息*/
@property(nonatomic,weak)UITextField *treatedMessageField;
@end

@implementation XHRIllDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initiateSettings];
    [self setupUI];
}
- (void)initiateSettings
{
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"疾病详情选择";

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"预约须知" style:UIBarButtonItemStyleDone target:self action:@selector(didClickRightButton:)];
}
- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
}
#pragma mark -
#pragma mark - 设置子控件
- (void)setupUI
{
    //设置标题label
    [self setupTitleLabel];
    //设置疾病细分的textField
    [self setupSelectIllField];
    //设置是否确诊textField
    [self setupIsSureField];
    //设置并发症textField
    [self setupSelectComplication];
    //设置是否接受过治疗textField
    [self setupIsTreated];
    //设置受治疗的详细信息
    [self setupTreatedMessageField];
    //设置申请就诊按钮
    [self setupBottomButton];
    //设置医生图片
    [self setupDoctorImage];
    //设置医生数量label
    [self setupDoctorNumberLabel];
}
#pragma mark -
#pragma mark - 设置标题label
- (void)setupTitleLabel
{
    //初始化label
    UILabel *label = [[UILabel alloc]init];
    label.text = [NSString stringWithFormat:@"疾病类型:%@",self.illName];
    label.font = [UIFont systemFontOfSize:16];
    label.textColor = [UIColor darkTextColor];
    
    [self.view addSubview:label];
    
    self.titlLabel = label;
    //设置约束
    [label makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(20);
        make.leading.offset(15);
    }];
}
#pragma mark -
#pragma mark - 设置疾病细分的textField
- (void)setupSelectIllField
{
    UITextField *textField = [self setupTextFieldWithType:XHRTextFieldRightViewTypeSigleButton placeholder:@"请选择疾病细分"];
    self.selectIllField = textField;
    
    [textField makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titlLabel.bottom).offset(30);
        make.leading.equalTo(self.titlLabel);
        make.trailing.offset(-15);
        make.height.equalTo(30);
    }];
}
#pragma mark -
#pragma mark - 设置是否确诊textField
- (void)setupIsSureField
{
    UITextField *textField = [self setupTextFieldWithType:XHRTextFieldRightViewTypeDoubleButtonIsSure placeholder:@"是否确诊"];
    
    self.isSureField = textField;
    
    [textField makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.selectIllField.bottom).offset(20);
        make.leading.equalTo(self.titlLabel);
        make.trailing.offset(-15);
        make.height.equalTo(30);
    }];
}

#pragma mark -
#pragma mark - 设置并发症textField
- (void)setupSelectComplication
{
    UITextField *textField = [self setupTextFieldWithType:XHRTextFieldRightViewTypeSigleButton placeholder:@"请选择并发症(可多选)"];
    
    self.selectComplicationField = textField;
    
    [textField makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.isSureField.bottom).offset(20);
        make.leading.equalTo(self.titlLabel);
        make.trailing.offset(-15);
        make.height.equalTo(30);
    }];
}
#pragma mark -
#pragma mark - 设置 TreatedMessageField
- (void)setupTreatedMessageField
{
    UITextField *textField = [self setupTextFieldWithType:XHRTextFieldRightViewTypeSigleButton placeholder:@"请选择治疗方式"];
    self.treatedMessageField = textField;
    
    [textField makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.isTreatedField.bottom).offset(20);
        make.leading.equalTo(self.titlLabel);
        make.trailing.offset(-15);
        make.height.equalTo(30);
    }];
    
    textField.hidden = YES;
    
}
#pragma mark -
#pragma mark - 设置是否接受过治疗textField
- (void)setupIsTreated
{
    
    UITextField *textField = [self setupTextFieldWithType:XHRTextFieldRightViewTypeDoubleButtonIsTreated placeholder:@"是否接受过治疗"];
    
  
   self.isTreatedField = textField;
    
   [textField makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.selectComplicationField.bottom).offset(20);
        make.leading.equalTo(self.titlLabel);
        make.trailing.offset(-15);
        make.height.equalTo(30);
    }];
}
#pragma mark -
#pragma mark - 设置底部就诊申请按钮
- (void)setupBottomButton
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.backgroundColor = [UIColor lightGrayColor];
    [button setTitle:@"就诊申请" forState:UIControlStateNormal];
    button.layer.cornerRadius = 5;
    button.layer.masksToBounds = YES;
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(didClickBottomButton:) forControlEvents:UIControlEventTouchUpInside];
    self.bottomButton = button;
    [self.view addSubview:button];
    
    [button makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.offset(-30);
        make.centerX.equalTo(self.view);
        make.leading.offset(20);
        make.trailing.offset(-20);
        make.height.equalTo(40);
    }];
}
#pragma mark -
#pragma mark - 设置底部匹配的医生的数目label
- (void)setupDoctorNumberLabel
{
    //初始化底部label
    UILabel *doctorNumberLabel = [[UILabel alloc]init];
    doctorNumberLabel.textAlignment = NSTextAlignmentCenter;
    doctorNumberLabel.text = @"重庆诊所为您匹配到0名医生";
    doctorNumberLabel.textColor = [UIColor lightGrayColor];
    doctorNumberLabel.font = [UIFont systemFontOfSize:13];
    self.doctorNumberLabel = doctorNumberLabel;
    [self.view addSubview:doctorNumberLabel];
    
    //设置约束
    [doctorNumberLabel makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.leading.offset(0);
        make.bottom.equalTo(self.doctorImageView.top).offset(-10);
        make.height.equalTo(30);
    }];
}
#pragma mark -
#pragma mark - setupDoctorImage
- (void)setupDoctorImage
{
    UIImageView *doctoarImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"illness_img_person.png"]];
    self.doctorImageView = doctoarImage;
    [self.view addSubview:doctoarImage];
    
    doctoarImage.contentMode = UIViewContentModeScaleAspectFit;
    [doctoarImage makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.offset(0);
        make.bottom.equalTo(self.bottomButton.top).offset(-10);
    }];
}
#pragma mark -
#pragma mark - 设置文本框的方法
- (UITextField *)setupTextFieldWithType:(XHRTextFieldRightViewType)type placeholder:(NSString *)placeholder
{
    __weak typeof(self) weakSelf = self;
    XHRIllDetailTextField *textField = [[XHRIllDetailTextField alloc]init];
    textField.type = type;
    
    textField.illDetailTextFieldBlock = ^(BOOL isTreated){
        if (isTreated) weakSelf.treatedMessageField.hidden = NO;
        else weakSelf.treatedMessageField.hidden = YES;
    };
    //设置占位文字属性
    NSMutableDictionary *propertyDict = [NSMutableDictionary dictionary];
    propertyDict[NSFontAttributeName] = [UIFont systemFontOfSize:14];
    [textField setupPlaceholderAttributes:propertyDict.copy placeholder:placeholder];
    [self.view addSubview:textField];
    return textField;
}
#pragma mark -
#pragma mark - 监听按钮的点击
- (void)didClickBottomButton:(UIButton *)sender
{
    NSLog(@"%s",__func__);
}
- (void)didClickRightButton:(UIBarButtonItem *)sender
{
    NSLog(@"%s",__func__);
}
@end
